<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    *{margin:0;padding:0;}
    #parent{
        /* position: relative; */
        width:300px;
        height:300px;
        background: red;
    }
    #child{
        position: absolute;
        width:100px;
        margin-left: 100px;
        left:100px;
        top:100px;
        height:100px;
        background: yellow;
    }
    </style>
</head>
<body>
    <div id="parent">
        <div id="child"></div>
    </div>
<!-- offsetParent获取定位的父元素
     offsetleft 返回元素的相对定位父元素水平偏移位置
     offsettop 返回元素相对定位的父元素垂直偏移的位置
     offsetWidth 只读
-->
    <script>
        var child=document.getElementById("child");
        var parent=child.offsetParent;
        var offsetLeft=child.offsetLeft;
        var offsetTop=child.offsetTop;
        var offsetWidth=child.offsetWidth;
        console.log(parent);
        console.log(offsetLeft);
        console.log(offsetTop);
        child.offsetWidth=300;
        child.offsetTop=400;
    </script>
</body>
</html>